package com.smile.stream.exercises;



import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Vector;
import java.util.stream.Collectors;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2021/10/8 16:24
 */
public class Demo1 {

     public static final List<String> stringList= Arrays.asList("Java"," Python "," go" ,"","shell","go");


    /**
     * 1针对字符串 转小写并去除首尾空格，并过滤空字符串，把结果收集成一个集合
     * 2针对字符串 转小写并去除首尾空格，并过滤空字符串，把结果收集成一个线程安全的集合（Vector）
     * 3针对字符串 转小写并去除首尾空格，并过滤空字符串，把结果收集成一个set
     * 4针对字符串 转小写并去除首尾空格，并过滤空字符串，且去重 把结果收集成一个以“,”拼接的字符串
     */
    public static void main(String[] args) {
        function1();
        function2();
        function3();
        function4();
    }

    private static void function4() {
        System.out.println("function4");
        String collect = stringList
                .stream()
                .map(String::trim)
                .map(String::toLowerCase)
                .filter(StringUtils::isNotBlank)
                .distinct()
                .collect(Collectors.joining(","));
        System.out.println(collect);
    }

    private static void function3() {
        System.out.println("function3");
        HashSet<String> collect = stringList
                .stream()
                .map(String::trim)
                .map(String::toLowerCase)
                .filter(StringUtils::isNotBlank)
                .collect(Collectors.toCollection(HashSet::new));
        System.out.println(collect);
    }

    private static void function2() {
        System.out.println("function2");
        Vector<String> collect = stringList
                .stream()
                .map(String::trim)
                .map(String::toLowerCase)
                .filter(StringUtils::isNotBlank)
                .collect(Collectors.toCollection(Vector::new));
        System.out.println(collect);
    }

    private static void function1() {
        System.out.println("function1");
        List<String> collect = stringList
                .stream()
                .map(String::trim)
                .map(String::toLowerCase)
                .filter(StringUtils::isNotBlank)
                .collect(Collectors.toList());
        System.out.println(collect);
    }
}
